package com.googlecode.cswish.util.crosssite;

import java.util.LinkedHashMap;
import java.util.Map;

import com.googlecode.cswish.struts.spring.Executor;

public class CrossSiteLRUCacheMap<V> extends CrossSiteCacheMap<V> {

	private static final long serialVersionUID = -5080617900844430315L;

	public CrossSiteLRUCacheMap(Map<String, V> initValues, final int maxEntries) {
		super(initValues, new Executor<Map<String,V>, Object>() {
			@Override
			public Map<String, V> execute(Object parameters) {
				// TODO: thread issue, add synchronized to get method?
				Map<String, V> cache = new LinkedHashMap<String, V>(maxEntries*3/2, 0.7f, true) {
					private static final long serialVersionUID = 6127624656572230287L;

					@Override
				    protected boolean removeEldestEntry(Map.Entry<String, V> eldest) {
				        return size() > maxEntries;
				    }
				};
				return cache;
			}
		});
	}
}